src/app/layout/text-statistics/text-statistics.component.ts
| selector | app-text-statistics |
| styleUrls | text-statistics.component.scss |
| templateUrl | ./text-statistics.component.html |
Properties |
|
Methods |
|
constructor(_textService: TextService, router: Router, _location: Location, modalService: NgbModal)
|
||||||||||||||||||||
|
Parameters :
|
| backClicked |
backClicked()
|
|
Returns :
void
|
| Public chartClicked | ||||||||
chartClicked(e: any)
|
||||||||
|
Parameters :
Returns :
void
|
| Public chartHovered | ||||||||
chartHovered(e: any)
|
||||||||
|
Parameters :
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| onResize | ||||||||
onResize(event: )
|
||||||||
|
Parameters :
Returns :
void
|
| textLevel |
textLevel(score: number, words: number)
|
|
Returns :
void
|
| updateBarChart | ||||||||||||||||||||||||
updateBarChart(awl: number, hi: number, med: number, low: number, noCategory: number)
|
||||||||||||||||||||||||
|
Parameters :
Returns :
void
|
| Private updaTeLabels |
updaTeLabels()
|
|
Returns :
void
|
| updatePieChart | ||||||||||||||||||||||||
updatePieChart(awl: number, hi: number, med: number, low: number, noCategory: number)
|
||||||||||||||||||||||||
|
Parameters :
Returns :
void
|
| awlPercentage |
awlPercentage:
|
Type : number
|
| Public BACK_LABEL |
BACK_LABEL:
|
Default value : Back
|
| backLabel |
backLabel:
|
Type : string
|
| Public barChartData |
barChartData:
|
Type : any[]
|
| Public barChartLabels |
barChartLabels:
|
Type : string[]
|
| Public barChartLegend |
barChartLegend:
|
Default value : true
|
| Public barChartOptions |
barChartOptions:
|
Type : any
|
| Public barChartType |
barChartType:
|
Default value : bar
|
| closeResult |
closeResult:
|
Type : string
|
| Public ENHANCETEXT_LABEL |
ENHANCETEXT_LABEL:
|
Type : string
|
Default value : Enhanced Text
|
| enhanceTextLabel |
enhanceTextLabel:
|
Type : string
|
| hiPercentage |
hiPercentage:
|
Type : number
|
| lowPercentage |
lowPercentage:
|
Type : number
|
| medPercentage |
medPercentage:
|
Type : number
|
| noCategoryPercentage |
noCategoryPercentage:
|
Type : number
|
| Public pieChartData |
pieChartData:
|
Type : number[]
|
| Public pieChartLabels |
pieChartLabels:
|
Type : string[]
|
| Public pieChartType |
pieChartType:
|
Default value : pie
|
| Public router |
router:
|
Type : Router
|
| showDiv |
showDiv:
|
Type : boolean
|
| showOnlyIcons |
showOnlyIcons:
|
Type : boolean
|
| text |
text:
|
Type : IText
|
| textColor |
textColor:
|
Type : string
|
| textLVL |
textLVL:
|
Type : string
|
import { Component, OnInit } from '@angular/core';
import { TextService, IText } from '../../shared'
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import { DecimalPipe } from '@angular/common';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-text-statistics',
templateUrl: './text-statistics.component.html',
styleUrls: ['./text-statistics.component.scss']
})
export class TextStatisticsComponent implements OnInit {
public static BACK_LABEL = ' Back';
public static readonly ENHANCETEXT_LABEL: string = ' Enhanced Text';
public pieChartLabels: string[] = ['Academic Word', 'High Freq.', 'Medium Freq.', 'Low Freq.', 'Names & Off-List'];
public pieChartData: number[];
public pieChartType = 'pie';
public barChartOptions: any = {
scaleShowVerticalLines: false,
responsive: true
};
public barChartLabels: string[] = ['Academic Word', 'High Freq.', 'Medium Freq.', 'Low Freq.', 'Off-List'];
public barChartData: any[];
public barChartType = 'bar';
public barChartLegend = true;
text: IText;
showDiv: boolean;
textLVL: string;
textColor: string;
showOnlyIcons: boolean;
backLabel: string = TextStatisticsComponent.BACK_LABEL;
enhanceTextLabel: string = TextStatisticsComponent.ENHANCETEXT_LABEL;
awlPercentage: number;
hiPercentage: number;
medPercentage: number;
lowPercentage: number;
noCategoryPercentage: number;
closeResult: string;
constructor(private _textService: TextService, public router: Router, private _location: Location, private modalService: NgbModal) { }
ngOnInit() {
window.scrollTo(0, 0);
this.text = this._textService.resultText;
if (!this.text) {
return;
} else {
this.textLevel(this.text.fleschReadingScore, this.text.words.length);
}
this.showDiv = true;
this.showOnlyIcons = window.innerWidth <= 680;
this.updaTeLabels();
if (!this.text) {
return;
} else {
this.updateBarChart(this.text.statistics.wordCount.awl, this.text.statistics.wordCount.hi,
this.text.statistics.wordCount.med, this.text.statistics.wordCount.low, this.text.statistics.wordCount.noCategory);
this.updatePieChart(this.text.statistics.wordPercentage.awl, this.text.statistics.wordPercentage.hi,
this.text.statistics.wordPercentage.med, this.text.statistics.wordPercentage.low, this.text.statistics.wordPercentage.noCategory);
}
}
/*
80-100: Beginner Lever
70-79: Intermediate Level
60-69: Upper intermediate Level
30-59: Advanced Level
0--29: College Level
*/
textLevel(score: number, words: number) {
if (score <= 29 && score >= 1) {
this.textLVL = 'College Level';
this.textColor = 'red';
} else if (score <= 59 && score >= 30) {
this.textLVL = 'Advanced Level';
this.textColor = 'orange';
} else if (score <= 69 && score >= 60) {
this.textLVL = 'Upper intermediate Level';
this.textColor = 'yellow';
} else if (score <= 79 && score >= 70) {
this.textLVL = 'Intermed iate Level';
this.textColor = 'green';
} else if (score === 0) {
if (words < 100) {
this.textLVL = 'it is not applicable for texts under 100 words.'
} else if (words > 100) {
this.textLVL = 'impossible to comprehend. (more sentences needed)'
}
} else {
this.textLVL = 'Beginner Level';
this.textColor = 'blue';
}
}
backClicked() {
this._location.back();
}
onResize(event) {
this.showOnlyIcons = window.innerWidth <= 680;
this.updaTeLabels();
event.target.innerWidth;
}
private updaTeLabels(): void {
this.backLabel = this.showOnlyIcons ? '' : TextStatisticsComponent.BACK_LABEL;
this.enhanceTextLabel = this.showOnlyIcons ? '' : TextStatisticsComponent.ENHANCETEXT_LABEL;
}
// events for Pie Chart
public chartClicked(e: any): void {
console.log(e);
}
public chartHovered(e: any): void {
console.log(e);
}
// Update Pie chart
updateBarChart(awl: number, hi: number, med: number, low: number, noCategory: number) {
this.barChartData = [
{ data: [awl, hi, med, low, noCategory], label: '# of Words in different Category' },
];
}
updatePieChart(awl: number, hi: number, med: number, low: number, noCategory: number) {
this.pieChartData = [awl * 100, hi * 100, med * 100, low * 100, noCategory * 100]
}
}
<!--if it sees the object it will show the result, else it prompt the user to go back-->
<div *ngIf="text; else elseBlock">
<div class="row">
<div class="col-6 col-sm-7">
<h1 class="font-responsive">Text Statistics</h1>
</div>
<div class="col-6 col-sm-5" (window:resize)="onResize($event)">
<div class="float-right">
<button type="button" class="btn btn-warning" (click)="backClicked()">
<i class="fa fa-step-backward" aria-hidden="true"></i>{{backLabel}}</button>
<button type="button" class="btn btn-success" [routerLink]="['/enhanced-text-result']">
<i class="fa fa-file-text" aria-hidden="true"></i> {{enhanceTextLabel}} </button>
</div>
</div>
</div>
<hr>
<div *ngIf="showDiv">
<!--Readability Score-->
<div class="card" style="margin: auto; margin-bottom: 3%; margin-top: 3%;">
<h3 class="card-header">Readability Scores
</h3>
<div class="card-block">
<div [ngSwitch]="true" style=" margin-bottom: 2%">
<div *ngSwitchCase="text.fleschReadingScore > 79">
<ngb-progressbar type="primary" [value]="text.fleschReadingScore" [striped]="true" [animated]="true">
<i>
<strong>{{text.fleschReadingScore | number:'1.0-2'}} / 100</strong>
</i>
</ngb-progressbar>
</div>
<div *ngSwitchCase="text.fleschReadingScore > 69 && text.fleschReadingScore < 80">
<ngb-progressbar type="success" [value]="text.fleschReadingScore" [striped]="true" [animated]="true">
<i>
<strong>{{text.fleschReadingScore | number:'1.0-2'}} / 100</strong>
</i>
</ngb-progressbar>
</div>
<div *ngSwitchCase="text.fleschReadingScore < 30">
<ngb-progressbar type="danger" [value]="text.fleschReadingScore" [striped]="true" [animated]="true">
<i>
<strong>{{text.fleschReadingScore | number:'1.0-2'}} / 100</strong>
</i>
</ngb-progressbar>
</div>
<div *ngSwitchDefault>
<ngb-progressbar type="warning" [value]="text.fleschReadingScore" [striped]="true" [animated]="true">
<i>
<strong>{{text.fleschReadingScore | number:'1.0-2'}} / 100</strong>
</i>
</ngb-progressbar>
</div>
</div>
<p>
<Strong>Total Readability Level: </Strong>
<strong [class]="textColor" style="font-size: 20px; font-weight: bold;">{{text.fleschReadingScore | number:'1.0-2'}}</strong>
</p>
<p>
<Strong>The text is appropriate for: </Strong>
<strong [class]="textColor" style="font-size: 20px; font-weight: bold;">{{textLVL}}</strong>
</p>
</div>
</div>
<!--Text Statistic-->
<div class="card">
<h3 class="card-header">Statistics</h3>
<div class="card-block">
<table class="table table-bordered" style="margin-bottom: 3%;">
<thead class="thead-default">
<tr>
<th>#</th>
<th>Word Count</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">AWL</th>
<td>{{text.statistics.wordCount.awl}}</td>
<td>{{(text.statistics.wordPercentage.awl * 100) | number:'1.0-2'}}%</td>
</tr>
<tr>
<th scope="row">High Freq.</th>
<td>{{text.statistics.wordCount.hi}}</td>
<td>{{(text.statistics.wordPercentage.hi * 100) | number:'1.0-2'}}%</td>
</tr>
<tr>
<th scope="row">Medium Freq.</th>
<td>{{text.statistics.wordCount.med}}</td>
<td>{{(text.statistics.wordPercentage.med * 100) | number:'1.0-2'}}%</td>
</tr>
<tr>
<th scope="row">Low Freq.</th>
<td>{{text.statistics.wordCount.low}}</td>
<td>{{(text.statistics.wordPercentage.low * 100) | number:'1.0-2'}}%</td>
</tr>
<tr>
<th scope="row">Names & off-list</th>
<td>{{text.statistics.wordCount.noCategory}}</td>
<td>{{(text.statistics.wordPercentage.noCategory * 100) | number:'1.0-2'}}%</td>
</tr>
</tbody>
</table>
<table class="table table-bordered">
<thead class="thead-default">
<tr>
<th>#</th>
<th>Words</th>
<th>Sentences</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Total</th>
<td>{{text.statistics.wordCount.total}}</td>
<td>{{text.sentenceCount}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row" style="margin-top: 3%;">
<div class="col col-md-6">
<div class="card mb-3">
<div class="card-header">
<i class="fa fa-fw fa-bar-chart fa-2x float-right"></i>
Bar Chart (#)
</div>
<div class="card-body">
<canvas baseChart [datasets]="barChartData" [labels]="barChartLabels" [options]="barChartOptions" [legend]="barChartLegend"
[chartType]="barChartType" (chartHover)="chartHovered($event)" (chartClick)="chartClicked($event)">
</canvas>
</div>
</div>
</div>
<div class="col col-md-6">
<div class="card mb-3">
<div class="card-header">
<i class="fa fa-fw fa-pie-chart fa-2x float-right"></i>
Pie Chart (%)
</div>
<div class="card-body">
<canvas baseChart [data]="pieChartData" [labels]="pieChartLabels" [chartType]="pieChartType" (chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"></canvas>
</div>
</div>
</div>
</div>
</div>
</div>
<!--if page refreshes it prompt the user to go to the previous page-->
<ng-template #elseBlock>
<div class="row">
<!-- <meta http-equiv="refresh" content="0;url=http://www.myvirs.com/dashboard" /> -->
<div class="col-6">
<h1>Oops!</h1>
</div>
<div class="col-6" (window:resize)="onResize($event)">
<div class="float-right">
<button type="button" class="btn btn-warning" (click)="backClicked()">
<i class="fa fa-step-backward" aria-hidden="true"></i> {{backLabel}}</button>
</div>
</div>
</div>
<hr>
<div>
<h4> Redirecting to homepage in 3 seconds...</h4>
</div>
</ng-template>